package com.htj.util;

import java.util.HashMap;
import java.util.Map;
import org.springframework.web.client.RestTemplate;

public class WeChatSendMessage {
   private static final String MSGTYPE = "text";
   private static final String CREATE_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=";

   public String sendWeChatTextCardMessage(String touser, String toparty, String totag, String title, String description, String msgurl, String btntxt) {
      String result = "";
      RestTemplate restTemplate = new RestTemplate();
      String ACCESS_TOKEN = null;

      try {
         ACCESS_TOKEN = WeChatToken.get_accessToken();
      } catch (Exception var17) {
         return result;
      }

      if (ACCESS_TOKEN == null) {
         return "";
      } else {
         String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + ACCESS_TOKEN;

         try {
            String agentid = "1000083";
            Map body = new HashMap();
            body.put("touser", touser);
            body.put("toparty", toparty);
            body.put("totag", totag);
            body.put("msgtype", "textcard");
            body.put("agentid", agentid);
            Map textcard = new HashMap();
            textcard.put("title", title);
            textcard.put("description", description);
            textcard.put("url", msgurl);
            textcard.put("btntxt", btntxt);
            body.put("textcard", textcard);
            body.put("enable_id_trans", "0");
            body.put("enable_duplicate_check", "0");
            body.put("duplicate_check_interval", "1800");
            String response = (String)restTemplate.postForObject(url, body, String.class, new Object[0]);
            result = response;
         } catch (Exception var16) {
            var16.printStackTrace();
         }

         return result;
      }
   }
}
